#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QSqlDatabase tmpDB = QSqlDatabase::addDatabase("QSQLITE");
    tmpDB.setDatabaseName(DBNAME);

    tmpDB.open();

    this->dbModel = new QSqlQueryModel;
    dbModel->setQuery("SELECT * FROM employee",tmpDB);
    dbModel->setHeaderData(0,Qt::Horizontal,tr("序号"));
    dbModel->setHeaderData(1,Qt::Horizontal,tr("姓名"));
    dbModel->setHeaderData(2,Qt::Horizontal,tr("身份证号"));
    dbModel->setHeaderData(3,Qt::Horizontal,tr("职业"));
    dbModel->setHeaderData(4,Qt::Horizontal,tr("生日"));
    dbModel->setHeaderData(5,Qt::Horizontal,tr("薪资"));
    dbModel->setHeaderData(6,Qt::Horizontal,tr("备注"));

    ui->tableView_sqlite->setModel(this->dbModel);
    ui->tableView_sqlite->show();
}

MainWindow::~MainWindow()
{
    delete ui;
}
